BeginMarkedContent(String,KeyValuePair<String,PdfBasicObject>[]) Method (PdfGraphics)
Begins a marked-content sequence with an associated property list in the content stream.
Here is an example that shows how to create a tagged PDF document with marked content with properties:
''' <summary>
''' Creates a tagged PDF document with marked content with properties.
''' </summary>
Public Shared Sub CreateTaggedPdfWithProperties()
' create new PDF document
Using document As New Vintasoft.Imaging.Pdf.PdfDocument()
' add new page to the PDF document
document.Pages.Add(New System.Drawing.SizeF(250, 250))
' create marked information object
Dim markInfo As New Vintasoft.Imaging.Pdf.Tree.PdfMarkInformation(document)
markInfo.IsMarked = True
' add marked information object to the PDF document
document.MarkedInformation = markInfo
' get graphics object associated with page
Using graphics As Vintasoft.Imaging.Pdf.Drawing.PdfGraphics = document.Pages(0).GetGraphics()
' create properties for marked content
Dim markedContentProperties As System.Collections.Generic.KeyValuePair(Of String, Vintasoft.Imaging.Pdf.BasicTypes.PdfBasicObject)() = New System.Collections.Generic.KeyValuePair(Of String, Vintasoft.Imaging.Pdf.BasicTypes.PdfBasicObject)() {New System.Collections.Generic.KeyValuePair(Of String, Vintasoft.Imaging.Pdf.BasicTypes.PdfBasicObject)("Subtype", New Vintasoft.Imaging.Pdf.BasicTypes.PdfName("Header")), New System.Collections.Generic.KeyValuePair(Of String, Vintasoft.Imaging.Pdf.BasicTypes.PdfBasicObject)("Attached", New Vintasoft.Imaging.Pdf.BasicTypes.PdfArray(document, New Vintasoft.Imaging.Pdf.BasicTypes.PdfName("Top"))), New System.Collections.Generic.KeyValuePair(Of String, Vintasoft.Imaging.Pdf.BasicTypes.PdfBasicObject)("Type", New Vintasoft.Imaging.Pdf.BasicTypes.PdfName("Pagination"))}
' begin the marked content with properties
graphics.BeginMarkedContent("Artifact", markedContentProperties)
' get the PDF font
Dim pdfFont As Vintasoft.Imaging.Pdf.Tree.Fonts.PdfFont = document.FontManager.GetStandardFont(Vintasoft.Imaging.Pdf.Tree.Fonts.PdfStandardFontType.TimesRoman)
' draw a text string
graphics.DrawString("Header text string", pdfFont, 12, New Vintasoft.Imaging.Pdf.Drawing.PdfBrush(System.Drawing.Color.Green), New System.Drawing.PointF(25, 50))
' end the marked content
graphics.EndMarkedContent()
End Using
' save document
document.SaveChanges("D:\testTaggedPdf.pdf")
End Using
End Sub
/// <summary>
/// Creates a tagged PDF document with marked content with properties.
/// </summary>
public static void CreateTaggedPdfWithProperties()
{
// create new PDF document
using (Vintasoft.Imaging.Pdf.PdfDocument document = new Vintasoft.Imaging.Pdf.PdfDocument())
{
// add new page to the PDF document
document.Pages.Add(new System.Drawing.SizeF(250, 250));
// create marked information object
Vintasoft.Imaging.Pdf.Tree.PdfMarkInformation markInfo =
new Vintasoft.Imaging.Pdf.Tree.PdfMarkInformation(document);
markInfo.IsMarked = true;
// add marked information object to the PDF document
document.MarkedInformation = markInfo;
// get graphics object associated with page
using (Vintasoft.Imaging.Pdf.Drawing.PdfGraphics graphics = document.Pages[0].GetGraphics())
{
// create properties for marked content
System.Collections.Generic.KeyValuePair<string, Vintasoft.Imaging.Pdf.BasicTypes.PdfBasicObject>[] markedContentProperties =
new System.Collections.Generic.KeyValuePair<string, Vintasoft.Imaging.Pdf.BasicTypes.PdfBasicObject>[]{
new System.Collections.Generic.KeyValuePair<string, Vintasoft.Imaging.Pdf.BasicTypes.PdfBasicObject>(
"Subtype", new Vintasoft.Imaging.Pdf.BasicTypes.PdfName("Header")),
new System.Collections.Generic.KeyValuePair<string, Vintasoft.Imaging.Pdf.BasicTypes.PdfBasicObject>(
"Attached", new Vintasoft.Imaging.Pdf.BasicTypes.PdfArray(document, new Vintasoft.Imaging.Pdf.BasicTypes.PdfName("Top"))),
new System.Collections.Generic.KeyValuePair<string, Vintasoft.Imaging.Pdf.BasicTypes.PdfBasicObject>(
"Type", new Vintasoft.Imaging.Pdf.BasicTypes.PdfName("Pagination"))
};
// begin the marked content with properties
graphics.BeginMarkedContent("Artifact", markedContentProperties);
// get the PDF font
Vintasoft.Imaging.Pdf.Tree.Fonts.PdfFont pdfFont = document.FontManager.GetStandardFont(
Vintasoft.Imaging.Pdf.Tree.Fonts.PdfStandardFontType.TimesRoman);
// draw a text string
graphics.DrawString(
"Header text string",
pdfFont,
12,
new Vintasoft.Imaging.Pdf.Drawing.PdfBrush(System.Drawing.Color.Green),
new System.Drawing.PointF(25, 50));
// end the marked content
graphics.EndMarkedContent();
}
// save document
document.SaveChanges(@"D:\testTaggedPdf.pdf");
}
}
Target Platforms: .NET9; .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5